package com.qf.shopuser.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.qf.common.result.ResultEntity;
import com.qf.entity.User;
import com.qf.shopuser.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/userController")
public class UserController {
    @Autowired
    private UserService userService;

//    @RequestMapping("/user")
//    public String userTest() {
//        return "ok";
//    }

    @RequestMapping("/addUser")
    //从前端传过来的是json数据 要用这个注解接受
    public ResultEntity addUser(@RequestBody User user) {
        boolean insert = userService.insert(user);
        return ResultEntity.success(insert);
    }

    @RequestMapping("/getUser")
    public Page<User> getUserPage(@RequestBody Page<User> page) {
        return userService.selectPage(page);

    }

    @RequestMapping("/getUserByUsername")
    public User getUserByUsername(@RequestParam String username) {
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq("username", username);
        return userService.selectOne(entityWrapper);
    }
}
